<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::Autoload</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveSupport::Autoload 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activesupport/lib/active_support/dependencies/autoload_rb.html">activesupport/lib/active_support/dependencies/autoload.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="Autoload.html">Autoload</a> and eager load conveniences for your
library.</p>

<p>This module allows you to define autoloads based on <a
href="../Rails.html">Rails</a> conventions (i.e. no need to define the path
it is automatically guessed based on the filename) and also define a set of
constants that needs to be eager loaded:</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">MyLib</span>
  <span class="ruby-identifier">extend</span> <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Autoload</span>

  <span class="ruby-identifier">autoload</span> :<span class="ruby-constant">Model</span>

  <span class="ruby-identifier">eager_autoload</span> <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">autoload</span> :<span class="ruby-constant">Cache</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Then your library can be eager loaded by simply calling:</p>

<pre>MyLib.eager_load!</pre>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Autoload.html#method-i-autoload">autoload</a>,
              </li>
            
              
              <li>
                <a href="Autoload.html#method-i-autoload_at">autoload_at</a>,
              </li>
            
              
              <li>
                <a href="Autoload.html#method-i-autoload_under">autoload_under</a>,
              </li>
            
              
              <li>
                <a href="Autoload.html#method-i-autoloads">autoloads</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Autoload.html#method-i-eager_autoload">eager_autoload</a>,
              </li>
            
              
              <li>
                <a href="Autoload.html#method-i-eager_load-21">eager_load!</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-autoload">
            
              <b>autoload</b>(const_name, path = @_at_path)
            
            <a href="Autoload.html#method-i-autoload" name="method-i-autoload" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-autoload_source')" id="l_method-i-autoload_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L35" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-autoload_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">autoload</span>(<span class="ruby-identifier">const_name</span>, <span class="ruby-identifier">path</span> = <span class="ruby-ivar">@_at_path</span>)
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">path</span>
    <span class="ruby-identifier">full</span> = [<span class="ruby-identifier">name</span>, <span class="ruby-ivar">@_under_path</span>, <span class="ruby-identifier">const_name</span>.<span class="ruby-identifier">to_s</span>].<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;::&quot;</span>)
    <span class="ruby-identifier">path</span> = <span class="ruby-constant">Inflector</span>.<span class="ruby-identifier">underscore</span>(<span class="ruby-identifier">full</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@_eager_autoload</span>
    <span class="ruby-ivar">@_autoloads</span>[<span class="ruby-identifier">const_name</span>] = <span class="ruby-identifier">path</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">super</span> <span class="ruby-identifier">const_name</span>, <span class="ruby-identifier">path</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-autoload_at">
            
              <b>autoload_at</b>(path)
            
            <a href="Autoload.html#method-i-autoload_at" name="method-i-autoload_at" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-autoload_at_source')" id="l_method-i-autoload_at_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L55" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-autoload_at_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">autoload_at</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-ivar">@_at_path</span>, <span class="ruby-identifier">old_path</span> = <span class="ruby-identifier">path</span>, <span class="ruby-ivar">@_at_path</span>
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-ivar">@_at_path</span> = <span class="ruby-identifier">old_path</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-autoload_under">
            
              <b>autoload_under</b>(path)
            
            <a href="Autoload.html#method-i-autoload_under" name="method-i-autoload_under" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-autoload_under_source')" id="l_method-i-autoload_under_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L48" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-autoload_under_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">autoload_under</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-ivar">@_under_path</span>, <span class="ruby-identifier">old_path</span> = <span class="ruby-identifier">path</span>, <span class="ruby-ivar">@_under_path</span>
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-ivar">@_under_path</span> = <span class="ruby-identifier">old_path</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-autoloads">
            
              <b>autoloads</b>()
            
            <a href="Autoload.html#method-i-autoloads" name="method-i-autoloads" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-autoloads_source')" id="l_method-i-autoloads_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L73" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-autoloads_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 73</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">autoloads</span>
  <span class="ruby-ivar">@_autoloads</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-eager_autoload">
            
              <b>eager_autoload</b>()
            
            <a href="Autoload.html#method-i-eager_autoload" name="method-i-eager_autoload" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-eager_autoload_source')" id="l_method-i-eager_autoload_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L62" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-eager_autoload_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 62</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">eager_autoload</span>
  <span class="ruby-identifier">old_eager</span>, <span class="ruby-ivar">@_eager_autoload</span> = <span class="ruby-ivar">@_eager_autoload</span>, <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-ivar">@_eager_autoload</span> = <span class="ruby-identifier">old_eager</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-eager_load-21">
            
              <b>eager_load!</b>()
            
            <a href="Autoload.html#method-i-eager_load-21" name="method-i-eager_load-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-eager_load-21_source')" id="l_method-i-eager_load-21_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb58c0ed4a167ff04b7cbf4e4560fffb68109638/activesupport/lib/active_support/dependencies/autoload.rb#L69" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-eager_load-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/dependencies/autoload.rb, line 69</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">eager_load!</span>
  <span class="ruby-ivar">@_autoloads</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">require</span> <span class="ruby-identifier">file</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    